package com.zxl.grocery.microservice.admin.rpc;

import com.zxl.grocery.microservice.admin.rpc.service.PermissionService;
import com.zxl.grocery.microservice.api.authority.PermissionInfo;
import com.zxl.grocery.microservice.api.user.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by zxl on 2017/10/13 0013.
 */
@RestController
@RequestMapping("api")
public class UserRest {
    @Autowired
    private PermissionService permissionService;

    @RequestMapping(value = "/user/username/{username}",method = RequestMethod.GET, produces="application/json")//produces 表示将功能处理方法将生产json格式的数据，此时根据请求头中的Accept进行匹配，如请求头“Accept:application/json”时即可匹配
    public  @ResponseBody
    UserInfo getUserByUsername(@PathVariable("username")String username) {
        return permissionService.getUserByUsername(username);
    }

    @RequestMapping(value = "/permissions", method = RequestMethod.GET)
    public @ResponseBody
    List<PermissionInfo> getAllPermission(){
        return permissionService.getAllPermission();
    }


    @RequestMapping(value = "/user/un/{username}/permissions", method = RequestMethod.GET)
    public @ResponseBody
    List<PermissionInfo> getPermissionByUsername(@PathVariable("username") String username){
        return permissionService.getPermissionByUsername(username);
    }
}
